<template>
  <div class="contentManage">
    <div class="contentManage-tab">
      <van-tabs v-model:active="activeItem">
        <van-tab title="文章">
          <div class="contentManage-tab-articles">
            <div class="contentManage-tab-articles-item" :key="index" v-for="(item,index) in articles">
              <div class="contentManage-tab-articles-item-title">
                <h4>
                  {{item.title}}
                </h4>
              </div>
              <div class="contentManage-tab-articles-item-content">
                <div class="contentManage-tab-articles-item-content-text">
                  {{item.content.text}}
                </div>
                <div class="contentManage-tab-articles-item-content-pic">
                  <img :src="item.coverUrl">
                </div>
              </div>
              <div class="contentManage-tab-articles-item-other">
                <div>
                  <span>{{item.like}}&nbsp;赞</span>
                  <span>&emsp;·&emsp;</span>
                  <span>{{item.comment}}&nbsp;评论</span>
                  <span>&emsp;·&emsp;</span>
                  <span>{{item.date}}&nbsp;</span>
                </div>
                <div class="articleDel" @click="handleDelArticle(item._id)">
                  删除
                </div>
              </div>
            </div>
          </div>
        </van-tab>
        <van-tab title="视频">
          <div class="contentManage-tab-videos">
            <div>
              <div class="contentManage-tab-videos-item" 
                  v-for="(item,index) in videos"
                  v-show="index%2 == 0"
                  :key="index"
                >
                <div class="contentManage-tab-videos-item-delButton" @click="handleDelVideo(item._id)">x</div>
                <Vlog
                  
                  :title="item.title"
                  :coverUrl="item.coverUrl"
                  :tag="item.tag"
                />
              </div>
            </div>
            <div>
              <div class="contentManage-tab-videos-item"
                v-for="(item,index) in videos"
                v-show="index%2 != 0"
                :key="index"
              >
                <div class="contentManage-tab-videos-item-delButton" @click="handleDelVideo(item._id)">x</div>
                <Vlog
                  :title="item.title"
                  :coverUrl="item.coverUrl"
                  :tag="item.tag"
                />
              </div>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>
<script>
import { Tab, Tabs, Dialog } from "vant";
import Vlog from "@/components/Vlog";
import { getUserArticles, delArticles, getUserVideos, delVideo } from "@/service/user";
export default {
  components:{
    [Tab.name]:Tab,
    [Tabs.name]:Tabs,
    Vlog
  },
  data(){
    return {
      activeItem:"",
      articles:[],
      videos:[]
    }
  },
  mounted(){
    getUserArticles().then(res=>{
      this.articles = res;
    })
    getUserVideos().then(res=>{
      console.log(res);
      this.videos = res;
    })
  },
  methods:{
    handleDelArticle(id){
      Dialog.confirm({
        message:"删除就找不回来了，确定吗？"
      }).then(()=>{
        delArticles(id).then(res1=>{
          if(res1.acknowledged){
            getUserArticles().then(res2=>{
              this.articles = res2;
            })
          }
        })
      }).catch(()=>{
        
      })
    },
    handleDelVideo(id){
      Dialog.confirm({
        message:"删除就找不回来了，确定吗？"
      }).then(()=>{
        delVideo(id).then(res1=>{
          if(res1.acknowledged){
            getUserVideos().then(res2=>{
              this.videos = res2;
            })
          }
        })
      }).catch(()=>{
        
      })
    }
  }
}
</script>
<style lang="less">
  .contentManage{
    background: #EFEFEF;
    .contentManage-tab-articles{
      border-top: 1px solid #999;
      .contentManage-tab-articles-item{
        padding: 0px 8px;
        background: #fff;
        overflow: hidden;
        margin: 0 4px 8px 4px;
        border-radius: 10px;
        .contentManage-tab-articles-item-title{
          text-align: left;
        }
        .contentManage-tab-articles-item-content{
          display: flex;
          .contentManage-tab-articles-item-content-text{
            flex: 1;
            height: 86px;
            word-break:break-all;
            display:-webkit-box;
            -webkit-line-clamp:4;
            -webkit-box-orient:vertical;
            overflow:hidden;
          }
          .contentManage-tab-articles-item-content-pic{
            width:130px;
            height: 86px;
            overflow: hidden;
            margin-left: 8px;
            border-radius: 10px;
            img{
              width: 100%;
            }
          }
        }
        .contentManage-tab-articles-item-other{
          padding: 8px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          .articleDel{
            width: 80px;
            background: #FF0000;
            padding:4px 0;
            color:#fff;
            font-weight: 600;
            border-radius: 5px;
          }
        }
      }
    }
    .contentManage-tab-videos{
      display:flex;
      justify-content: center;
      >div{
        width: 45%;
        margin: 0 8px;
        .contentManage-tab-videos-item{
          position: relative;
          .contentManage-tab-videos-item-delButton{
            position: absolute;
            top: 0;
            right: 0;
            width: 30px;
            height: 30px;
            background: black;
            z-index:99;
            margin: 0;
            border-radius: 0 0 0 100% / 0 0 0 100%;
            color: #fff;
            font-size: 20px;
            background: #FF0000;
          }
        }
        >div{
          >div{
            margin: 8px 0;
          }
        }
      }
    }
  }
</style>